<template>
  <div>
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      style="text-align: left"
    >
      <el-form-item label="合同标题">
        <el-input
          v-model="formInline.titleContract"
          placeholder="请输入合同标题"
        ></el-input>
      </el-form-item>
      <el-form-item label="对方单位">
        <el-input
          v-model="formInline.oppositeUnit"
          placeholder="请输入对方单位"
        ></el-input>
      </el-form-item>
      <el-form-item label="对方负责人">
        <el-input
          v-model="formInline.oppositeParty"
          placeholder="请输入对方负责人"
        ></el-input>
      </el-form-item>
      <el-form-item label="经办人">
        <el-input
          v-model="formInline.agent"
          placeholder="请输入经办人"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          style="background-color: green; color: white"
          icon="el-icon-search"
          @click="list"
          >查询</el-button
        >
        <el-button style="color: gray" icon="el-icon-refresh">重置</el-button>
      </el-form-item>
    </el-form>
    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="number" label="合同编号" align="center">
        </el-table-column>
        <el-table-column prop="titleContract" label="合同标题" align="center">
        </el-table-column>
        <el-table-column prop="oppositeUnit" label="对方单位" align="center">
        </el-table-column>
        <el-table-column prop="oppositeParty" label="对方负责人" align="center">
        </el-table-column>
        <el-table-column prop="contClassId" label="合同类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.contClassId == 1">采购合同</span>
            <span v-if="scope.row.contClassId == 2">财务类合同</span>
          </template>
        </el-table-column>
        <el-table-column prop="signTime" label="签订日期" align="center">
        </el-table-column>
        <el-table-column prop="agent" label="经办人" align="center">
        </el-table-column>
        <el-table-column prop="state" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.state == 1">待审批</span>
            <span v-if="scope.row.state == 2">已通过</span>
            <span v-if="scope.row.state == 3">已拒绝</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.state == 1">
              <el-button
                type="text"
                style="color: orange"
                @click="examine(scope.row)"
                >查看</el-button
              >
              <el-button
                type="text"
                style="color: green"
                @click="pass(scope.row)"
                >通过</el-button
              >
              <el-button
                type="text"
                style="color: red"
                @click="refuse(scope.row)"
                >拒绝</el-button
              >
            </span>
            <span v-if="scope.row.state == 2">
              <el-button
                type="text"
                style="color: orange"
                @click="examine(scope.row)"
                >查看</el-button
              >
              <el-button
                :disabled="true"
                type="text"
                style="color: green"
                @click="pass(scope.row)"
                >通过</el-button
              >
              <el-button
                :disabled="true"
                type="text"
                style="color: red"
                @click="refuse(scope.row)"
                >拒绝</el-button
              >
            </span>
            <span v-if="scope.row.state == 3">
              <el-button type="text" style="color: orange" @click="examine"
                >查看</el-button
              >
              <el-button
                :disabled="true"
                type="text"
                style="color: green"
                @click="pass"
                >通过</el-button
              >
              <el-button
                :disabled="true"
                type="text"
                style="color: red"
                @click="refuse"
                >拒绝</el-button
              >
            </span>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-dialog
      width="600px"
      title="详情信息"
      :visible.sync="dialogFormVisible3"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="180px"
        style="width: 600px; margin: 2px auto"
      >
        <el-form-item label="合同编号" prop="equipmentCoding">
          {{ form.number }}
        </el-form-item>
        <el-form-item label="合同标题" prop="originalNum">
          {{ form.titleContract }}
        </el-form-item>
        <el-form-item label="对方单位" prop="equipmentName">
          {{ form.oppositeUnit }}
        </el-form-item>
        <el-form-item label="对方负责人" prop="equipmentLocaId">
          {{ form.oppositeParty }}
        </el-form-item>
        <el-form-item label="合同类型" prop="deviceType">
          <template slot-scope="scope">
            <span v-if="scope.row.contClassId == 1">采购合同</span>
            <span v-if="scope.row.contClassId == 2">财务类合同</span>
          </template>
        </el-form-item>
        <el-form-item label="签订日期" prop="detailedLocation">
          {{ form.signTime }}
        </el-form-item>
        <el-form-item label="经办人" prop="equipmentModel">
          {{ form.agent }}
        </el-form-item>
        <el-form-item label="状态" prop="equipmentBrand">
          <template slot-scope="scope">
            <span v-if="scope.row.state == 1">待审批</span>
            <span v-if="scope.row.state == 2">已通过</span>
            <span v-if="scope.row.state == 3">已拒绝</span>
          </template>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="countnum"
    >
    </el-pagination>
  </div>
</template>
<script>
import {
  GetShowContractManage,
  GetTotaocount,
  updContractManage,
} from "@/api/parkManage/ContractManage";
export default {
  data() {
    return {
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 0) {
          return "warning-row";
        } else if (rowIndex === 2) {
          return "success-row";
        }
        return "";
      },
      tableData: [],
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible3: false,
      multipleSelection: [],
      form: {
        id: "",
        personName: "",
        sex: "",
        idType: "",
        idNum: "",
        firmId: "",
        departId: "",
        roleId: "",
        phone: "",
        sortId: "",
        password: "",
      },
      formInline: {
        pageIndex: 1,
        pageSize: 2,
        titleContract: "",
        oppositeUnit: "",
        oppositeParty: "",
        agent: "",
      },
      countnum: 0,
      count: 0,

      update: {},
    };
  },
  created() {
    this.list();
    this.totalcount();
  },
  methods: {
    //显示
    list() {
      GetShowContractManage(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.list();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
    //全选/反选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //修改
    examine(row) {
      this.dialogFormVisible3 = true;
      this.form = row;
    },
    //重置密码
    chong() {
      if (this.multipleSelection.length != 1) {
        this.$message.error("请选择一条数据");
        return;
      }
      this.dialogFormVisible1 = true;
      this.multipleSelection.forEach((res) => {
        this.form = res;
      });
    },
    baocun1() {
      updUserManage(this.form).then((res) => {
        if (res.data) {
          this.$message({
            message: "重置密码成功",
            type: "success",
          });
          this.list();
          this.dialogFormVisible1 = false;
        } else {
          this.$message.error("重置密码失败");
        }
      });
    },
    //通过
    pass(row) {
      this.update = row;
      this.update.state = 2;
      updContractManage(this.update).then((res) => {
        if (res.data) this.list();
      });
    },
    //拒绝
    refuse(row) {
      this.update = row;
      this.update.state = 3;
      console.log(this.update);
      updContractManage(row).then((res) => {
        if (res.data) this.list();
      });
    },
  },
};
</script>
<style>
.el-table .warning-row {
  background: rgb(230, 253, 253);
}

.el-table .success-row {
  background: #f4ebf9;
}
</style>